package com.zhong.web.controller.monitor;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhong.common.annotation.Log;
import com.zhong.common.core.controller.BaseController;
import com.zhong.common.core.domain.AjaxResult;
import com.zhong.common.enums.BusinessType;
import com.zhong.common.utils.poi.ExcelUtil;
import com.zhong.system.domain.SysOperLog;
import com.zhong.system.service.SysOperLogService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 操作日志记录
 *
 * @author zhongzc
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/monitor/operlog")
public class SysOperlogController extends BaseController
{
    private final SysOperLogService service;

    @PreAuthorize("@ss.hasPermi('monitor:operlog:list')")
    @GetMapping("/list")
    public Page<SysOperLog> list(SysOperLog operLog)
    {
        return service.findPage(operLog);
    }

    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysOperLog operLog)
    {
        List<SysOperLog> list = service.selectOperLogList(operLog);
        ExcelUtil<SysOperLog> util = new ExcelUtil<SysOperLog>(SysOperLog.class);
        util.exportExcel(response, list, "操作日志");
    }

    @Log(title = "操作日志", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        service.deleteByIds(ids);
        return AjaxResult.success();
    }

    @Log(title = "操作日志", businessType = BusinessType.CLEAN)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
    @DeleteMapping("/clean")
    public AjaxResult clean()
    {
        service.clean();
        return success();
    }
}
